<?php 
require_once (dirname(__FILE__)."/services.php");
class seminars_RouterExtension extends Extension {
    public function apply(&$context, Chain $chain) {
        $context['rule']['{^/seminars/*$}'] = dirname(__FILE__)."/actions.php";
        $context['rule']['{^/seminars/([0-9]+)/$}'] = dirname(__FILE__)."/actions.php";
        $chain->next($context);
    }
}

class seminarsFeature extends Feature {
    public function registerExtension() {
        $this->extensions = Array( 
              	 new seminars_RouterExtension("com.yizin.platform.router")
		);
    }
    
    public function registerExtendable() {
    }
    
    public function init() {
    	$conn = getDBConnection();
		$conn->query('drop table if exists seminars_profiles;');
		$conn->query('drop table if exists seminars_sessions;');
		$conn->query('drop table if exists seminars_sessions_speakers;');
		$conn->query('drop table if exists seminars_sessions_profiles;');
		$conn->query('drop table if exists seminars_sessions_comments');
		
		$query_seminars_profiles = 'CREATE TABLE seminars_profiles (
			id_seminar BIGINT PRIMARY KEY AUTO_INCREMENT,
			start_time DATETIME NOT NULL,
			duration INT NOT NULL,
			location VARCHAR(255) NOT NULL
		)CHARSET=utf8;';
		
		$query_seminars_sessions = 'CREATE TABLE seminars_sessions(
			id_session BIGINT PRIMARY KEY AUTO_INCREMENT,
			id_seminar BIGINT NOT NULL,
			title VARCHAR(255) NOT NULL
		)CHARSET=utf8;';
		
		$query_seminars_sessions_speakers = 'CREATE TABLE seminars_sessions_speakers  (
			id BIGINT PRIMARY KEY AUTO_INCREMENT,
			id_session BIGINT NOT NULL,
			id_person BIGINT NOT NULL
		)CHARSET=utf8;';
		
		$query_seminars_sessions_profiles = 'CREATE TABLE seminars_sessions_profiles (
			id BIGINT PRIMARY KEY AUTO_INCREMENT,
			id_seminar BIGINT NOT NULL,
			profile_key VARCHAR(255) NOT NULL,
			profile_value TEXT NULL
		)CHARSET=utf8;';
		
		$query_seminars_sessions_comments = 'CREATE TABLE seminars_sessions_comments (
			id_comment BIGINT PRIMARY KEY AUTO_INCREMENT,
			id_reply BIGINT,
			date_time DATETIME NOT NULL,
			id_person BIGINT NULL,
			content TEXT NOT NULL
		)CHARSET=utf8;';
		
    	$conn->query($query_seminars_profiles);
		$conn->query($query_seminars_sessions);
		$conn->query($query_seminars_sessions_speakers);
		$conn->query($query_seminars_sessions_profiles);
		
		$conn->disconnect();
	}
    
    public function destroy() {
    	$conn=getDBConnection();
		
		$conn->query('drop table if exists seminars_profiles;');
		$conn->query('drop table if exists seminars_sessions;');
		$conn->query('drop table if exists seminars_sessions_speakers;');
		$conn->query('drop table if exists seminars_sessions_profiles;');
		
		$conn->disconnect();
    }
}

$featureClass = "seminarsFeature";
$featureName = "Seminars";
$featureIntroduction = "seminars feature";
?>
